
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

abstract class ViewPagerAdapterLazyFragment : Fragment() {

    final override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)
//        L.d(javaClass.simpleName + " setUserVisibleHint(), isVisibleToUser = " + isVisibleToUser)
        if (view != null) {
            if (isVisibleToUser) {
                onFragmentShow()
            } else {
                onFragmentHide()
            }
        }
    }

    override fun onAttach(activity: Activity) {
        super.onAttach(activity)
//        L.d(javaClass.simpleName + " onAttach()")
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        L.d(javaClass.simpleName + " onCreate()")
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
//        L.d(javaClass.simpleName + " onCreateView()")
        return super.onCreateView(inflater, container, savedInstanceState)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
//        L.d(javaClass.simpleName + " onActivityCreated()")
    }

    final override fun onStart() {
        super.onStart()
//        L.d(javaClass.simpleName + " onStart()")
        if (userVisibleHint && view != null) {
            onFragmentShow()
        }
    }

    override fun onResume() {
        super.onResume()
//        L.d(javaClass.simpleName + " onResume()")
    }

    override fun onPause() {
        super.onPause()
//        L.d(javaClass.simpleName + " onPause()")
    }

    final override fun onStop() {
        super.onStop()
//        L.d(javaClass.simpleName + " onStop()")
        if (userVisibleHint) {
            onFragmentHide()
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
//        L.d(javaClass.simpleName + " onDestroyView()")
    }

    override fun onDestroy() {
        super.onDestroy()
//        L.d(javaClass.simpleName + " onDestroy()")
    }

    override fun onDetach() {
        super.onDetach()
//        L.d(javaClass.simpleName + " onDetach()")
    }

    abstract fun onFragmentShow()

    abstract fun onFragmentHide()

}